$(function () {
  
    var diseaseId = getQueryString("diseaseId");
    console.log(diseaseId);
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/disease.do?method=findDiseaseByDiseaseId&diseaseId="+diseaseId,

        function (data) {
        	console.log(data)
         $("#disease_id").val(data[0].diseaseId),
	     $("#disease_name").val(data[0].diseaseName),
	     $("#category").val(data[0].category),
         $("#content").val(data[0].content),
         $("#distribution").val(data[0].distribution),
	     $("#img_path").val(data[0].imgPath)
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {

        $.post(
            "/citrusmonitor/disease.do?method=modify",
            {
            	"diseaseId": $("#disease_id").val(),
                "diseaseName": $("#disease_name").val(),
                "content": $("#content").val(),
                "category": $("#category").val(),
                "distribution": $("#distribution").val(),
                "imgPath": $("#img_path").val()
            },
           function(res){
                console.log(res);
                res = JSON.parse(res);
                if(res.status==1){
                    alert("信息提示修改成功");
                }else{
                    alert("信息提示修改失败");
                }}
        )
    })
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    console.log(reg );
    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}
